home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume89 / aplictns / hyphelp.2 < prev    next >
Internet Message Format  |  1989-10-25  |  63KB

  1. Path: xanth!uakari.primate.wisc.edu!brutus.cs.uiuc.edu!apple!sun-barr!newstop!sun!swap!page
  2. From: page%swap@Sun.COM (Bob Page)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v89i188:  hyperhelp - amiga help system, Part02/03
  5. Message-ID: <126802@sun.Eng.Sun.COM>
  6. Date: 25 Oct 89 17:05:44 GMT
  7. Sender: news@sun.Eng.Sun.COM
  8. Lines: 2235
  9. Approved: page@sun.com
  10.  
  11. Submitted-by: jap@syssun.cl.msu.edu (Joe A. Porkka)
  12. Posting-number: Volume 89, Issue 188
  13. Archive-name: applications/hyphelp.2
  14.  
  15. # This is a shell archive.
  16. # Remove anything above and including the cut line.
  17. # Then run the rest of the file through 'sh'.
  18. # Unpacked files will be owned by you and have default permissions.
  19. #----cut here-----cut here-----cut here-----cut here----#
  20. #!/bin/sh
  21. # shar: SHell ARchive
  22. # Run the following text through 'sh' to create:
  23. #    gc2.c
  24. #    gen.c
  25. #    getenv.c
  26. #    getfile.c
  27. #    grandcentral.c
  28. #    help.h
  29. # This is archive 2 of a 3-part kit.
  30. # This archive created: Wed Oct 25 10:02:51 1989
  31. echo "extracting gc2.c"
  32. sed 's/^X//' << \SHAR_EOF > gc2.c
  33. X/* These functions should be in grandcentral.c */
  34. X
  35. X#include <intuition/intuition.h>
  36. X#include <exec/io.h>
  37. X#include <exec/memory.h>
  38. X#include "help.h"
  39. X#include "helptext.h"
  40. X
  41. Xextern struct NewWindow nw;
  42. Xextern int debug, stdout;
  43. Xextern struct Screen *screen;
  44. Xextern struct MsgPort *mp;
  45. X
  46. Xextern ULONG ENVRefresh, ENVNumClicks, ENVAskFirst;
  47. Xextern struct Task *mytask;
  48. X
  49. X/* From print.c */
  50. Xextern struct IOStdReq *printreq;
  51. X/* grandcentral.c */
  52. Xextern short openroot, closeall, hideall, goaway, findabout, checkflags;
  53. Xextern int printing, printbuflen;
  54. Xextern u_char *printbuf;
  55. Xextern struct openwindows *printow;
  56. X
  57. X#define SETREFRESH(ow) ((struct openwindows *)ow)->flags|=ow_REFRESH
  58. X#define CLRREFRESH(ow) ((struct openwindows *)ow)->flags&=~ow_REFRESH
  59. X
  60. Xextern ULONG prevsecs, prevmicros;
  61. Xextern u_short clickx, clicky, clickcount;
  62. Xextern struct key key;
  63. X
  64. XULONG lastclicksecs, lastclickmicros;
  65. X
  66. X/* flipwindow()
  67. X   Flip a window between icon and full size.
  68. X   Also can be used to re-open hidden windows.
  69. X*/
  70. Xint
  71. Xflipwindow(tmpow,flag)
  72. X    struct openwindows *tmpow;
  73. X    int flag; /* 0==flip window, 1==re-open window */
  74. X{
  75. X    short left, top, wide, high;
  76. X
  77. X    nw.Screen=screen;
  78. X    SETREFRESH(tmpow);
  79. X    if(tmpow->window) {
  80. X    getdims(tmpow);
  81. X    left=tmpow->LeftEdge,
  82. X    top =tmpow->TopEdge,
  83. X    wide=tmpow->Width,
  84. X    high=tmpow->Height;
  85. X
  86. X#ifdef DEBUG1
  87. X    dmsg(1,"flip window\n");
  88. X#endif
  89. X    CWS(tmpow->window, tmpow->doc->savefont);
  90. X    tmpow->window=0;
  91. X    nw.LeftEdge=tmpow->saveleft;
  92. X    nw.TopEdge=tmpow->savetop;
  93. X    nw.Width=tmpow->savewide;
  94. X    nw.Height=tmpow->savehigh;
  95. X
  96. X    tmpow->saveleft=left;
  97. X    tmpow->savetop=top;
  98. X    tmpow->savewide=wide;
  99. X    tmpow->savehigh=high;
  100. X    } else {
  101. X#ifdef DEBUG1
  102. X    dmsg(1,"Open hidden window\n");
  103. X#endif
  104. X    nw.LeftEdge=tmpow->LeftEdge;
  105. X    nw.TopEdge=tmpow->TopEdge;
  106. X    nw.Width=tmpow->Width;
  107. X    nw.Height=tmpow->Height;
  108. X    nw.MinWidth=tmpow->MinWidth;
  109. X    nw.MinHeight=tmpow->MinHeight;
  110. X    }
  111. X
  112. X    /* Open full size window if ICONIZED or hidden and !iconized */
  113. X    if( (flag && !(tmpow->flags & ow_ICONIZED)) || ((!flag) && (tmpow->flags & ow_ICONIZED)) ) {
  114. X#ifdef DEBUG1
  115. X    dmsg(1,"OPEN BIG WINDOW\n");
  116. X#endif
  117. X    if(!flag) {
  118. X        nw.MinWidth=tmpow->saveminwidth;
  119. X        nw.MinHeight=tmpow->saveminheight;
  120. X    }
  121. X    nw.DetailPen=-1;
  122. X    nw.BlockPen=-1;
  123. X    nw.Flags=HELPWINDOWFLAGS | ENVRefresh;
  124. X    nw.Title=tmpow->doc->body->comment;
  125. X    nw.FirstGadget=tmpow->scroll;
  126. X    tmpow->scroll->NextGadget=tmpow->up;
  127. X    tmpow->up->NextGadget=tmpow->down;
  128. X    tmpow->down->NextGadget=0;
  129. X    tmpow->icon->NextGadget=0;
  130. X    tmpow->window=OpenWindow(&nw);
  131. X    if(tmpow->window==0) {
  132. X#ifdef DEBUG5
  133. X        dmsg(5,"OPEN BIG WINDOW failed!\n");
  134. X#endif
  135. X        return 0;
  136. X    }
  137. X    tmpow->window->UserPort=mp;
  138. X    ModifyIDCMP(tmpow->window, HELPWINDOWIDCMPFLAGS);
  139. X    AddGadget(tmpow->window,tmpow->icon,0);      /* Put the ICON gadget at the head of the class */
  140. X    RefreshGList(tmpow->icon,tmpow->window,0,1); /* ...and make it appear */
  141. X    SetDrMd(tmpow->window->RPort,JAM1);
  142. X    if(tmpow->doc->savefont) SetFont(tmpow->window->RPort,tmpow->doc->savefont);
  143. X    tmpow->window->UserData=(BYTE *)tmpow;
  144. X    if(!flag) tmpow->flags &= ~ow_ICONIZED;
  145. X    if((tmpow->doc->linespace+tmpow->window->RPort->Font->tf_YSize)*3 < tmpow->window->MinHeight) {
  146. X        tmpow->window->RPort->TxHeight=tmpow->window->RPort->Font->tf_YSize+tmpow->doc->linespace;
  147. X    }
  148. X    makemenu(tmpow->window);
  149. X    } else {
  150. X#ifdef DEBUG1
  151. X    dmsg(1,"OPEN ICON WINDOW\n");
  152. X#endif
  153. X    nw.DetailPen=0;
  154. X    nw.BlockPen=3;
  155. X    nw.Flags=HELPICONWINDOWFLAGS;
  156. X    nw.FirstGadget=0;
  157. X    nw.Title=tmpow->doc->body->comment;
  158. X    nw.MinHeight=2;
  159. X    nw.MinWidth=2;
  160. X    tmpow->window=OpenWindow(&nw);
  161. X    if(tmpow->window==0) {
  162. X#ifdef DEBUG5
  163. X        dmsg(5,"OPEN ICON WINDOW failed!\n");
  164. X#endif
  165. X        return 0;
  166. X    }
  167. X    tmpow->window->UserPort=mp;
  168. X    ModifyIDCMP(tmpow->window, HELPICONWINDOWIDCMPFLAGS);
  169. X    AddGadget(tmpow->window,tmpow->icon,0);      /* Put the ICON gadget at the head of the class */
  170. X    RefreshGList(tmpow->icon,tmpow->window,0,1); /* ...and make it appear */
  171. X    tmpow->window->UserData=(BYTE *)tmpow;
  172. X    if(!flag) tmpow->flags |= ow_ICONIZED;
  173. X    makemenu(tmpow->window);
  174. X    }
  175. X    getdims(tmpow);
  176. X    return 1;
  177. X}
  178. X
  179. Xvoid
  180. Xgetdims(tmpow)
  181. X    struct openwindows *tmpow;
  182. X{
  183. X    LockLayerRom(tmpow->window->WLayer);
  184. X    tmpow->Height = tmpow->window->Height;
  185. X    tmpow->Width = tmpow->window->Width;
  186. X    tmpow->LeftEdge = tmpow->window->LeftEdge;
  187. X    tmpow->TopEdge = tmpow->window->TopEdge;
  188. X    tmpow->MinWidth= tmpow->window->MinWidth;
  189. X    tmpow->MinHeight= tmpow->window->MinHeight;
  190. X    UnlockLayerRom(tmpow->window->WLayer);
  191. X}
  192. X
  193. Xvoid
  194. Xscrollit(ow)
  195. X    struct openwindows *ow;
  196. X{
  197. X    int line;
  198. X    line= (((struct PropInfo *)ow->scroll->SpecialInfo)->VertPot*(ow->doc->l_count - ow->high)) >>16;
  199. X    moveto(ow,line);
  200. X    SETREFRESH(ow);
  201. X}
  202. X
  203. X/*
  204. Xvoid
  205. Xcancelprintjob() {
  206. X    printitout();
  207. X    if(printing) {
  208. X    dmsg(1,"Cancel print job! printing=%ld\n",printing);
  209. X    printing=0;
  210. X    if(printow) {
  211. X        closewindow(printow);
  212. X        printow=0;
  213. X        dmsg(1,"About to dnit print\n");
  214. X        printdnit();
  215. X    }
  216. X    dmsg(1,"About to free printbuffer...");
  217. X    if(printbuf && printbuflen) FreeMem(printbuf,printbuflen);
  218. X    printbuf=0;
  219. X    printbuflen=0;
  220. X    dmsg(1,"Freed!\n");
  221. X    } else {
  222. X       dmsg(1,"CANCEL PRINT WHILE NOT PRINTING==0!\n");
  223. X    }
  224. X    printitout();
  225. X}
  226. X*/
  227. Xvoid checkclicks(im,tmpow)
  228. X    struct IntuiMessage *im;
  229. X    struct openwindows *tmpow;
  230. X{
  231. X    if (!(im->Seconds>lastclicksecs || (im->Seconds==lastclicksecs && im->Micros>=lastclickmicros))) {
  232. X    return; /* Avoid allowing user to accidently (or purposely)doubleclick a second time on something,
  233. X           before we get to take care of the first
  234. X         */
  235. X    }
  236. X    if(prevsecs==0) {
  237. X    clickcount=1;
  238. X    clickx=im->MouseX;
  239. X    clicky=im->MouseY;
  240. X    }
  241. X    if(     ((clickx-im->MouseX)*(clickx-im->MouseX)+
  242. X        (clicky-im->MouseY)*(clicky-im->MouseY))
  243. X    <
  244. X        ((tmpow->window->RPort->TxHeight)*(tmpow->window->RPort->TxHeight))
  245. X    ) {
  246. X    if(DoubleClick(prevsecs,prevmicros,im->Seconds,im->Micros) || ENVNumClicks==1) {
  247. X        clickcount++;
  248. X        if(clickcount>=ENVNumClicks) {
  249. X        clickcount=0;
  250. X        prevsecs=0; /* Prevent triple clicks */
  251. X#ifdef DEBUG1
  252. X        dmsg(1,"SELECT CLICK\n");
  253. X#endif
  254. X        findword(tmpow,(int)im->MouseX,(int)im->MouseY, &key);
  255. X        if(key.name) {
  256. X#ifdef DEBUG1
  257. X            dmsg(1,"Type is ");
  258. X#endif
  259. X            if(key.type) {
  260. X            int len;
  261. X            u_char *tmpcmd;
  262. X
  263. X            dmsg(1,"execute '%s'",key.name);
  264. X            if(askforexec(tmpow->window,key.name)) {
  265. X                len=strlen(key.name)+17;
  266. X                tmpcmd=(u_char *)AllocMem(len,0);
  267. X                if(tmpcmd) {
  268. X                strncpy(tmpcmd,"run <nil: >nil: ",17);
  269. X                strncpy(tmpcmd+16,key.name,len);
  270. X                Execute(tmpcmd,0,stdout);
  271. X#ifdef DEBUG1
  272. X                dmsg(1,"\nReturncode==%ld\n",IoErr());
  273. X#endif
  274. X                if(tmpcmd) FreeMem(tmpcmd,len);
  275. X                } else {
  276. X#ifdef DEBUG5
  277. X                dmsg(5,"** Out-of-mem, could not execute!\n");
  278. X#endif
  279. X                }
  280. X                CurrentTime(&lastclicksecs,&lastclickmicros);
  281. X            } else {
  282. X                dmsg(1,"Execute aborted!\n");
  283. X                DisplayBeep(tmpow->window->WScreen);
  284. X            }
  285. X            } else {
  286. X            struct openwindows *tmpow2;
  287. X            u_char *tmpname, len;
  288. X#ifdef DEBUG1
  289. X            dmsg(1,"reference");
  290. X            dmsg(1,".\nFileName='%s'\n",key.name);
  291. X            dmsg(1,"Opening up the reference\n");
  292. X#endif
  293. X            tmpname=strchr(key.name,(u_char)',');
  294. X            if(tmpname) {
  295. X                len=tmpname-key.name-1; /*Length of label*/
  296. X                while(*tmpname==' ' || *tmpname=='\t') tmpname++;
  297. X                tmpow2=getfile(tmpname);
  298. X            } else {
  299. X                tmpow2=getfile(key.name);
  300. X            }
  301. X            CurrentTime(&lastclicksecs,&lastclickmicros);
  302. X            if(tmpow2==0) {
  303. X#ifdef DEBUG1
  304. X                dmsg(1,"Could not open referenced file.\n");
  305. X#endif
  306. X                DisplayBeep(tmpow->window->WScreen);
  307. X            } else {
  308. X                tmpow=tmpow2;
  309. X                if(tmpname) {
  310. X#ifdef DEBUG1
  311. X                dmsg(1,"GOTO ");
  312. X#endif
  313. X                if(tmpow->doc->labs && tmpow->doc->lab_count) {
  314. X                    int j;
  315. X#ifdef DEBUG1
  316. X                    if(debug) {
  317. X                    int i;
  318. X                    dmsg(1,"Searching for label '");
  319. X                    for(i=0;i<len;i++) dmsg(1,"%lc",key.name[i]);
  320. X                    dmsg(1,"'.\n");
  321. X                    }
  322. X#endif
  323. X                    for(j=0;j<tmpow->doc->lab_count;j++) {
  324. X                    if(strnicmp(key.name,tmpow->doc->labs[j].name,len)==0) {
  325. X                        tmpow->doc->pnum=tmpow->doc->labs[j].paragraph;
  326. X                        tmpow->doc->lnum=tmpow->doc->labs[j].line;
  327. X                        fixscrollgadget(tmpow);
  328. X#ifdef DEBUG1
  329. X                        dmsg(1,"Found!, pnum=%ld, lnum=%ld.\n",tmpow->doc->pnum, tmpow->doc->lnum);
  330. X#endif
  331. X                        break;
  332. X                    }
  333. X                    }
  334. X                }
  335. X                }
  336. X                refresh(tmpow);
  337. X            }
  338. X            }
  339. X            if(key.length) {
  340. X#ifdef DEBUG1
  341. X            dmsg(1,"Freeing memory for key==%ld.\n",key.length);
  342. X#endif
  343. X            FreeMem(key.name,key.length);
  344. X            key.length=0;
  345. X            }
  346. X        } else {
  347. X#ifdef DEBUG1
  348. X            dmsg(1,"FileName='<nil>'.\n");
  349. X#endif
  350. X        }
  351. X        } else {
  352. X        prevsecs=im->Seconds;
  353. X        prevmicros=im->Micros;
  354. X        }
  355. X    } else {
  356. X        prevsecs=im->Seconds;
  357. X        prevmicros=im->Micros;
  358. X        clickcount=1;
  359. X    }
  360. X    } else {
  361. X    clickcount=0;
  362. X    prevsecs=prevmicros=0;
  363. X    }
  364. X}
  365. X
  366. Xvoid
  367. Xprocessmenuevent(menunumber,MenuStrip, tmpow)
  368. X    USHORT menunumber;
  369. X    struct Menu *MenuStrip;
  370. X    struct openwindows *tmpow;
  371. X{
  372. X    struct MenuItem *item, *ItemAddress();
  373. X    if(menunumber!=MENUNULL) {
  374. X
  375. X    while(menunumber!=MENUNULL) {
  376. X        item=ItemAddress(MenuStrip,menunumber);
  377. X#ifdef DEBUG1
  378. X        dmsg(1,"Menu menunumber=%lx.\n",menunumber);
  379. X        dmsg(1,"Menu==%ld, Item=%ld, SubItem=%ld",
  380. X        MENUNUM(menunumber), ITEMNUM(menunumber), SUBNUM(menunumber));
  381. X#endif
  382. X
  383. X        switch(MENUNUM(menunumber)) {
  384. X        case 0: /* MENU: Control */
  385. X            switch(ITEMNUM(menunumber)) {
  386. X            case 0: /* ITEM: Open A file */
  387. X#ifdef DEBUG1
  388. X                dmsg(1,"Open a file -- Not Implemented yet!\n");
  389. X#endif
  390. X                break;
  391. X            case 1: /* ITEM: Open root file */
  392. X#ifdef DEBUG1
  393. X                dmsg(1,"Open root file!\n");
  394. X#endif
  395. X                openroot=1;
  396. X                checkflags++;
  397. X                break;
  398. X            case 2: /* ITEM: Close all windows */
  399. X#ifdef DEBUG1
  400. X                dmsg(1,"Close selected!\n");
  401. X#endif
  402. X                closeall=1;
  403. X                checkflags++;
  404. X                break;
  405. X            case 3: /* ITEM: Hide all windows */
  406. X#ifdef DEBUG1
  407. X                dmsg(1,"Hide selected!\n");
  408. X#endif
  409. X                hideall=1;
  410. X                break;
  411. X            case 4: /* ITEM: Go away completely */
  412. X#ifdef DEBUG1
  413. X                dmsg(1,"Go away\n");
  414. X#endif
  415. X                goaway=1;
  416. X                break;
  417. X            case 5: /* ITEM: About */
  418. X                dmsg(1,"About\n");
  419. X                findabout=1;
  420. X                break;
  421. X            }
  422. X            break;
  423. X        case 1: /* MENU: Print */
  424. X            switch(ITEMNUM(menunumber)) {
  425. X            case 0: /* ITEM: Print window */
  426. X                checkflags++;
  427. X                tmpow->flags|= ow_PRINTWINDOW;
  428. X                break;
  429. X            case 1: /* ITEM: Print file */
  430. X                checkflags++;
  431. X                tmpow->flags|= ow_PRINTFILE ;
  432. X                break;
  433. X            case 2: /* ITEM: Cancel prints */
  434. X                if(printing) printing=6;
  435. X                break;
  436. X            }
  437. X            break;
  438. X
  439. X        }
  440. X        menunumber=item->NextSelect;
  441. X    }
  442. X
  443. X    } else {
  444. X#ifdef DEBUG1
  445. X    dmsg(1,"No menu pick.\n");
  446. X#endif
  447. X    }
  448. X}
  449. SHAR_EOF
  450. echo "extracting gen.c"
  451. sed 's/^X//' << \SHAR_EOF > gen.c
  452. X/* HyperHelp -- Copyright 1989 Joe Porkka */
  453. X
  454. X/* gen.c -- General usage routines. Some are duplicates from the
  455. X        standard C library, but are duplicated here to avoid
  456. X        linking with the C library.
  457. X*/
  458. X
  459. Xchar *arg(len,str)
  460. X    register int *len;
  461. X    register char **str;
  462. X{
  463. X    register int x;
  464. X    register char *s,*a,quote=0;
  465. X
  466. X    x=*len; s=*str;
  467. X    while(x>=0 && (*s==' ' || *s=='\t' || *s=='\n')) {x--; s++;}
  468. X    if(*s=='\'' || *s=='"') {quote=*s++; x--;}
  469. X    a=s;
  470. X    if(quote) {
  471. X    while(x>=0 && (*s!='\'' && *s!='"')) {x--;s++;}
  472. X    } else {
  473. X    while(x>=0 && (*s!=' ' && *s!='\t' && *s!='\n')) {x--; s++;}
  474. X    }
  475. X    *s=0;
  476. X    *str=s+1;
  477. X    *len=x;
  478. X    return(a);
  479. X}
  480. X
  481. Xchar *
  482. Xstrchr(s,c)
  483. X    register char *s,c;
  484. X{
  485. X    if(s==0) return 0;
  486. X    while(*s!=0) if(*s++==c) return s;
  487. X    return 0;
  488. X}
  489. X
  490. Xint
  491. Xstrncpy(to,from,max)
  492. X    register char *to, *from;
  493. X    register int max;
  494. X{
  495. X    register int k;
  496. X
  497. X    for(k=0;k<max;k++)
  498. X    if( ( *to++ = *from++ )==0) break;
  499. X    return k;
  500. X}
  501. X
  502. Xint
  503. Xstrlen(to)
  504. X    register char *to;
  505. X{
  506. X    register int x=0;
  507. X    while(*to++) x++;
  508. X    return (x);
  509. X}
  510. X
  511. Xstrcmp(this,that)
  512. X    register char *this, *that;
  513. X{
  514. X    register int i,j;
  515. X
  516. X    if(this==0 && that==0) return(0);
  517. X    i=strlen(this);
  518. X    j=strlen(that);
  519. X    while(*this++==*that++ && i>0 && j>0) {
  520. X    i--; j--;
  521. X    };
  522. X    if(i==0 && j==0) return(0);
  523. X    if( *--this < *--that ) return(-1);
  524. X    if( *this>*that ) return(1);
  525. X    if(i) return(1); else return(-1);
  526. X}
  527. X
  528. Xint
  529. Xstrnicmp(this,that,n)
  530. X    register char *this, *that;
  531. X    register int n;
  532. X{
  533. X    register int i=0;
  534. X    register char a,b;
  535. X
  536. X    if(this==0 && that==0) return(0);
  537. X    while(i<n) {
  538. X    a=*this++;
  539. X    b=*that++;
  540. X    if(a!=b) {
  541. X        if(a==0) return -1;
  542. X        if(b==0) return  1;
  543. X        if(a>='a' && a<='z')
  544. X        a-=32;
  545. X        if(b>='a' && b<='z')
  546. X        b-=32;
  547. X
  548. X        if(a!=b) break;
  549. X    } else if(a==0) return 0;
  550. X    i++;
  551. X    };
  552. X    return (int) (a-b);
  553. X}
  554. X
  555. Xint
  556. Xstrfind(str,what)
  557. X    char *str, *what;
  558. X{
  559. X    register char a,b, *pos, *pat;
  560. X
  561. X    if(str==0 && what==0 || what==0) return(0);
  562. X    for(pos=str; *pos!=0; pos= ++str) {
  563. X    pat=what;
  564. X    while( (b=*pat++)!=0 ) {
  565. X        a=*pos++;
  566. X        if(a==0) return 1;
  567. X        if(a!=b) {
  568. X        if(a>='a' && a<='z')
  569. X            a-=32;
  570. X        if(b>='a' && b<='z')
  571. X            b-=32;
  572. X
  573. X        if(a!=b) break;
  574. X        }
  575. X    }
  576. X    if(b==0) return 0;
  577. X    }
  578. X    return 1;
  579. X}
  580. SHAR_EOF
  581. echo "extracting getenv.c"
  582. sed 's/^X//' << \SHAR_EOF > getenv.c
  583. X/* HyperHelp -- Copyright 1989 Joe Porkka */
  584. X
  585. X/* getenv.c -- reads the ENV: vars into internal variables */
  586. X
  587. X#include <exec/types.h>
  588. X#include <exec/tasks.h>
  589. X#include <graphics/text.h>
  590. X#include <exec/memory.h>
  591. X#include <libraries/dosextens.h>
  592. Xextern struct Task *mytask;
  593. X#define MEMF_NAMED 0x10000000
  594. X#define AllocMem allocmem
  595. X#define FreeMem freemem
  596. X
  597. X
  598. X/* DESCRIPTION OF ENV: VARIABLES:
  599. X   ==============================
  600. X
  601. X * NoSetFont        If this exists, then the FONT directive in files
  602. X            will be ignored.
  603. X
  604. X * Font = name.font n    Sets the default font for files that do not specify
  605. X            a font. If NoSetFont exists, then all files will
  606. X            use this font.
  607. X
  608. X * HotKey = code,qual    Sets the hotkey to scancode 'code' with
  609. X            'qual' qualifiers (exclusively) set.
  610. X
  611. X * RootFile = path    Sets what the root of the helpfiles are.
  612. X            This defaults to "help:toplevel"
  613. X
  614. X * Screen =        Can be set to WBENCHSCREEN or CUSTOMSCREEN.
  615. X
  616. X * Pen = n        Sets the default text pen color.
  617. X
  618. X * Paper = n        Sets the default 'paper' color.
  619. X
  620. X * Top            Sets the default position
  621. X * Left         and size of help windows.
  622. X * Width        These values are range checked
  623. X * Height        for safeties sake.
  624. X
  625. X * XInc         Sets the X and Y increments to offset
  626. X * YInc         windows to avoid overlaps.
  627. X
  628. X*/
  629. X
  630. X#define HELPCODE 0x5f
  631. X#define HELPQUAL 0x0040
  632. X#define ENVBUFSIZE 100
  633. X#define ROOTFILE "help:toplevel"
  634. X
  635. Xchar *envbuf;
  636. X
  637. Xint NoSetFont, NoHotKey, ScreenType, ENVAskFirst;
  638. X
  639. Xunsigned int HotKeyCode, HotKeyQual, PenColor;
  640. Xint ENVTop, ENVLeft, ENVWidth, ENVHeight, ENVXInc, ENVYInc;
  641. Xint ENVLspace,ENVNumClicks;
  642. Xunsigned char *ENVRootFile, *ENVIndexFile;
  643. Xstruct TextAttr *ENVFont;
  644. Xunsigned long ENVRefresh;
  645. X
  646. Xint nsetflag ;
  647. Xextern int oserr;
  648. Xextern int debug;
  649. X
  650. Xint
  651. Xgetenv() {
  652. X    int length;
  653. X    struct Process *myproc=(struct Process *)mytask;
  654. X    APTR tmpptr;
  655. X
  656. X    oserr=0;
  657. X    NoSetFont=0; NoHotKey=0;
  658. X    ENVAskFirst=1;
  659. X    ENVFont=0;
  660. X    PenColor=-1;
  661. X    ScreenType=0; /* WBenchscreen */
  662. X
  663. X    envbuf=(char *)AllocMem(ENVBUFSIZE,0);
  664. X    if(envbuf==0) return 0;
  665. X
  666. X    /* Disable the "Insert Volume ENV:" garbage */
  667. X    tmpptr=myproc->pr_WindowPtr;
  668. X#ifdef DEBUG1
  669. X    dmsg(1,"Process WindowPtr=0x%lx.\n",myproc->pr_WindowPtr);
  670. X#endif
  671. X    myproc->pr_WindowPtr= (APTR)-1; /* keep the requesters away */
  672. X    HotKeyCode = getnumvar("ENV:HELPHotKeyCode");
  673. X    if(oserr==218) {
  674. X    /* If ENV: not mounted, then don't keep trying to access it */
  675. X    FreeMem(envbuf,ENVBUFSIZE);
  676. X    envbuf=0;
  677. X    HotKeyCode= HELPCODE;
  678. X    HotKeyQual= HELPQUAL;
  679. X    myproc->pr_WindowPtr=tmpptr;
  680. X    return 0;
  681. X    }
  682. X    ENVAskFirst=0; /* Make it default to on, unless there is an envronment */
  683. X    if(oserr==205) { /* File did not exist */
  684. X    HotKeyCode= HELPCODE;
  685. X    }
  686. X    HotKeyQual = getnumvar("ENV:HELPHotKeyQual");
  687. X    if(oserr==205) { /* File did not exist */
  688. X    HotKeyQual= HELPQUAL;
  689. X    }
  690. X    PenColor   = getnumvar("ENV:HELPPenColor");
  691. X    if(oserr==205) {
  692. X#ifdef DEBUG5
  693. X    dmsg(5,"OSERR=205, pencolor=%ld\n",PenColor);
  694. X#endif
  695. X    PenColor=-1;
  696. X    }
  697. X    if(PenColor==0) PenColor=1;
  698. X#ifdef DEBUG1
  699. X    dmsg(1,"GETENV: Pencolor=%ld\n",PenColor);
  700. X#endif
  701. X    ENVTop      = getnumvar("ENV:HELPTop");
  702. X    ENVLeft      = getnumvar("ENV:HELPLeft");
  703. X    ENVWidth      = getnumvar("ENV:HELPWidth");
  704. X    ENVHeight      = getnumvar("ENV:HELPHeight");
  705. X    ENVXInc      = getnumvar("ENV:HELPXInc");
  706. X    ENVYInc      = getnumvar("ENV:HELPYInc");
  707. X    ENVLspace      = getnumvar("ENV:HELPLspace");
  708. X    ENVNumClicks  = getnumvar("ENV:HELPNumClicks");
  709. X    if(ENVNumClicks<1 || ENVNumClicks >4) ENVNumClicks=2;
  710. X
  711. X    length = getvar("ENV:HELPSCREEN");
  712. X    if(length) {
  713. X#ifdef DEBUG1
  714. X    /* dmsg(1,"Screen = '%s'\n",envbuf); */
  715. X#endif
  716. X    if(strfind(envbuf,"custom")==0) {
  717. X        ScreenType=1;
  718. X    }
  719. X    if(strfind(envbuf,"interlace")==0) {
  720. X        ScreenType|=2;
  721. X    }
  722. X    }
  723. X    length = getvar("ENV:HELPREFRESH");
  724. X    if(length) {
  725. X    if(strnicmp("smart_refresh",envbuf,13)==0 || strnicmp("smart",envbuf,5)==0) {
  726. X        ENVRefresh=1;
  727. X    }
  728. X    }
  729. X
  730. X    length=getvar("ENV:HELPNoSetFont");
  731. X    if(length==-1)
  732. X    NoSetFont=0;
  733. X    else
  734. X    NoSetFont=1;
  735. X
  736. X    length=getvar("ENV:HELPAskFirst");
  737. X    if(length==-1)
  738. X    ENVAskFirst=0;
  739. X    else
  740. X    ENVAskFirst=1;
  741. X
  742. X    length=getvar("ENV:HELPNoHotKey");
  743. X    if(length==-1)
  744. X    NoHotKey=0;
  745. X    else
  746. X    NoHotKey=1;
  747. X
  748. X    length=getvar("ENV:HELPFont");
  749. X    if(length==-1) {
  750. X    ENVFont=0;
  751. X    } else {
  752. X    int j,t;
  753. X
  754. X    envbuf[length]=0;
  755. X    for(j=0;envbuf[j]!=0 && envbuf[j]!=' ';j++);
  756. X    ENVFont=(struct TextAttr *)AllocMem(sizeof(struct TextAttr),MEMF_CLEAR | MEMF_NAMED,"getenv TextAttr");
  757. X    if(ENVFont) {
  758. X        ENVFont->ta_Name = (STRPTR) AllocMem(j,0|MEMF_NAMED,"getenv fontname");
  759. X        if(ENVFont->ta_Name) {
  760. X        strncpy(ENVFont->ta_Name,envbuf,j);
  761. X        ENVFont->ta_Name[j]=0;
  762. X
  763. X        dmsg(1,"getenv: Font name is '%s'\t",ENVFont->ta_Name);
  764. X
  765. X        while(envbuf[j]==' ')j++;
  766. X        t=0;
  767. X        while(envbuf[j]<='9' && envbuf[j]>='0') {
  768. X            t=t*10+ envbuf[j]-'0';
  769. X            j++;
  770. X        }
  771. X        ENVFont->ta_YSize=t;
  772. X
  773. X        dmsg(1,"getenv: Font height =%ld.\n",t);
  774. X
  775. X        } else {
  776. X        FreeMem(ENVFont,sizeof(struct TextAttr));
  777. X        ENVFont=0;
  778. X        }
  779. X    }
  780. X    }
  781. X    length=getvar("ENV:ENVRootFile");
  782. X    if(length==-1) {
  783. X    ENVRootFile=0;
  784. X    } else {
  785. X    envbuf[length]=0;
  786. X    ENVRootFile=(char *)AllocMem(length+1,0);
  787. X    if(ENVRootFile) strncpy(ENVRootFile,envbuf,length+1);
  788. X    }
  789. X    length=getvar("ENV:ENVIndexFile");
  790. X    if(length==-1) {
  791. X    ENVIndexFile=0;
  792. X    } else {
  793. X    envbuf[length]=0;
  794. X    ENVIndexFile=(char *)AllocMem(length+1,0);
  795. X    if(ENVIndexFile) strncpy(ENVIndexFile,envbuf,length+1);
  796. X    }
  797. X
  798. X#ifdef DEBUG1
  799. X    /* dmsg(1,"Done.\n"); */
  800. X#endif
  801. X    FreeMem(envbuf,ENVBUFSIZE);
  802. X    envbuf=0;
  803. X    myproc->pr_WindowPtr=tmpptr;
  804. X    return -1;
  805. X}
  806. X
  807. Xint
  808. Xgetnumvar(name)
  809. X    char *name;
  810. X{
  811. X    long length;
  812. X
  813. X    length=getvar(name);
  814. X#ifdef DEBUG1
  815. X    /* dmsg(1,"Getenv(%s)=",name); */
  816. X#endif
  817. X    if (length==-1) {
  818. X#ifdef DEBUG1
  819. X    /* dmsg(1,"<nil>\n"); */
  820. X#endif
  821. X    return 0;
  822. X    }
  823. X#ifdef DEBUG1
  824. X    /* dmsg(1,"'%s' ",envbuf); */
  825. X#endif
  826. X    return(getint(envbuf));
  827. X}
  828. X
  829. Xint
  830. Xgetvar(name)
  831. X    char *name;
  832. X{
  833. X    long fh, len;
  834. X
  835. X    oserr=0;
  836. X    fh=Open(name,1005);
  837. X    if(fh==0) {
  838. X    oserr=IoErr();
  839. X    return -1; /* value did not exist */
  840. X    }
  841. X
  842. X    len=Read(fh,envbuf,ENVBUFSIZE);
  843. X    if(len==ENVBUFSIZE) len--;
  844. X    envbuf[len]=0; /* It must be NULL terminated */
  845. X    Close(fh);
  846. X    return len;
  847. X}
  848. X
  849. Xint
  850. Xgetint(str)
  851. X    char *str;
  852. X{
  853. X    int val=0;
  854. X    int base=10;
  855. X
  856. X    while (*str==' ' || *str=='\t') str++;
  857. X    if(*str=='0') {
  858. X    base=8;
  859. X    str++;
  860. X    if(*str=='x' || *str=='X') {
  861. X        base=16;
  862. X        str++;
  863. X    }
  864. X    }
  865. X    while(*str!=0) {
  866. X    if( (base==10 && *str>='0' && *str<='9') || ( base==8 && *str>='0' && *str<='7'))
  867. X        val = val*base + (*str) - '0';
  868. X    else if (base==16) {
  869. X        if(*str>='0' && *str<='9')
  870. X        val = val*16 + (*str) - '0';
  871. X        else {
  872. X        *str &= ~32;
  873. X        if(*str>='A' && *str<='F')
  874. X            val = val*16 + (*str) - (10+'A');
  875. X        }
  876. X    } else
  877. X        break;
  878. X    str++;
  879. X    }
  880. X    dmsg(1,"VAL=%ld.\n",val);
  881. X    return val;
  882. X}
  883. X
  884. SHAR_EOF
  885. echo "extracting getfile.c"
  886. sed 's/^X//' << \SHAR_EOF > getfile.c
  887. X/* HyperHelp -- Copyright 1989 Joe Porkka */
  888. X
  889. X/* getfile.c -- Reads a file into memory + prepares it for use */
  890. X
  891. X#include <exec/types.h>
  892. X#include <exec/io.h>
  893. X#include <exec/memory.h>
  894. X#include <libraries/dos.h>
  895. X#include <libraries/dosextens.h>
  896. X#include <graphics/text.h>
  897. X#include <intuition/intuition.h>
  898. X#include "help.h"
  899. X#include "helptext.h"
  900. X#include "style.h"
  901. X
  902. Xextern int debug;
  903. Xextern long oserr;
  904. Xextern struct DOSerror errortext[];
  905. Xextern struct List windowhead;
  906. Xextern short screenWIDTH, screenHEIGHT;
  907. X
  908. X/* ENV: variables */
  909. Xextern int ENVTop, ENVLeft, ENVWidth, ENVHeight, ENVXInc, ENVYInc;
  910. Xextern int NoSetFont;
  911. Xextern struct TextAttr *ENVFont;
  912. X/**/
  913. X
  914. Xextern int TOP,LEFT,WIDTH,HEIGHT,XINC,YINC; /* FROM windows.c */
  915. Xint sleft, stop, swidth, sheight;
  916. X
  917. Xstruct openwindows *
  918. Xgetprintfile(name,wide)
  919. X    int wide;
  920. X    u_char *name;
  921. X{
  922. X    struct doc    *doc;
  923. X    struct openwindows *ow;
  924. X
  925. X    doc=getdatafile(name);
  926. X    if(doc==0) {
  927. X#ifdef DEBUG1
  928. X        dmsg(1,"getdatafile returns 0\n");
  929. X#endif
  930. X        return(0);
  931. X    }
  932. X    ow=(struct openwindows *)AllocMem(sizeof(struct openwindows),MEMF_CLEAR|MEMF_NAMED,"getfile1");
  933. X    if(ow==0) {
  934. X#ifdef DEBUG5
  935. X        dmsg(5,"OW IS ZERO!\n");
  936. X#endif
  937. X        freefile(doc);
  938. X        return(0);
  939. X    }
  940. X    ow->doc=doc;
  941. X
  942. X    AddTail(&windowhead,ow);
  943. X
  944. X    ow->doc->pnum=0; ow->doc->lnum=0;
  945. X
  946. X    if(format(doc,wide,0)==0) {
  947. X        closewindowsafely(ow);
  948. X        ow->window=0;
  949. X        Remove(ow);
  950. X        freefile(ow->doc);
  951. X        FreeMem(ow,sizeof(struct openwindows) );
  952. X        return(0);
  953. X    }
  954. X    return(ow);
  955. X}
  956. X
  957. Xstruct openwindows *
  958. Xgetfile(name)
  959. X    u_char *name;
  960. X{
  961. X    struct doc    *doc;
  962. X    struct Window      *win;
  963. X    struct openwindows *ow;
  964. X    int top,left,width,height;
  965. X    doc=getdatafile(name);
  966. X    if(doc==0) {
  967. X#ifdef DEBUG1
  968. X        dmsg(1,"getdatafile returns 0\n");
  969. X#endif
  970. X        return(0);
  971. X    }
  972. X    ow=(struct openwindows *)AllocMem(sizeof(struct openwindows),MEMF_CLEAR|MEMF_NAMED,"getfile1");
  973. X    if(ow==0) {
  974. X#ifdef DEBUG5
  975. X        dmsg(5,"OW IS ZERO!\n");
  976. X#endif
  977. X        freefile(doc);
  978. X        return(0);
  979. X    }
  980. X    ow->doc=doc;
  981. X    if(sleft!=-1) {
  982. X        left=sleft;
  983. X        top=stop;
  984. X        width=swidth;
  985. X        height=sheight;
  986. X    } else {
  987. X        if(LEFT+WIDTH>=screenWIDTH) {
  988. X            ENVLeft+=ENVXInc;
  989. X            if(ENVLeft+WIDTH>screenWIDTH) ENVLeft=0;
  990. X            LEFT=ENVLeft;
  991. X        }
  992. X        if(TOP+HEIGHT>=screenHEIGHT) {
  993. X            ENVTop+=ENVYInc;
  994. X            if(ENVTop+HEIGHT>screenHEIGHT) ENVTop=0;
  995. X            TOP=ENVTop;
  996. X        }
  997. X        top=TOP;
  998. X        left=LEFT;
  999. X        width=WIDTH;
  1000. X        height=HEIGHT;
  1001. X    }
  1002. X#ifdef DEBUG1
  1003. X    dmsg(1,"Makeing window (%ld,%ld,%ld,%ld)\n",left,top,width,height);
  1004. X#endif
  1005. X    win=makewindow(ow,left,top,width,height,doc->body->comment,&doc->body->font);
  1006. X    if(win==0) {
  1007. X#ifdef DEBUG5
  1008. X        dmsg(5,"Makewindow failed!\n");
  1009. X#endif
  1010. X        freefile(doc);
  1011. X        FreeMem(ow,sizeof(struct openwindows));
  1012. X        return(0);
  1013. X    }
  1014. X    if(ow->doc->linespace+win->RPort->TxHeight < win->MinHeight/3) {
  1015. X        win->RPort->TxHeight+=ow->doc->linespace;
  1016. X    }
  1017. X    if(sleft==-1) {
  1018. X        LEFT+=ENVXInc;
  1019. X        TOP+=ENVYInc;
  1020. X    }
  1021. X    AddTail(&windowhead,ow);
  1022. X
  1023. X    win->UserData=(BYTE *)ow;
  1024. X    ow->doc->pnum=0; ow->doc->lnum=0;
  1025. X
  1026. X    /* if(ow->doc->savefont) { */
  1027. X
  1028. X    if(sizewindow(win)==0) {
  1029. X        closewindowsafely(ow);
  1030. X        ow->window=0;
  1031. X        Remove(ow);
  1032. X        freefile(ow->doc);
  1033. X        FreeMem(ow,sizeof(struct openwindows) );
  1034. X        return(0);
  1035. X    }
  1036. X    return(ow);
  1037. X}
  1038. X
  1039. Xstruct doc *
  1040. Xgetdatafile(filename)
  1041. X    u_char *filename;
  1042. X{
  1043. X    struct doc *doc, *tmp;
  1044. X
  1045. X#ifdef DEBUG1
  1046. X    /* dmsg(1,"File name='%s'\n",filename); */
  1047. X#endif
  1048. X    if( (doc=readfile(filename))==0) {
  1049. X#ifdef DEBUG1
  1050. X        dmsg(1,"getfile: Open failed, returncode=%ld\n",oserr);
  1051. X#endif
  1052. X        goto fail;
  1053. X    }
  1054. X    tmp=pbreakfile(doc);
  1055. X    if(tmp==0) {
  1056. X#ifdef DEBUG1
  1057. X        dmsg(1,"getfile: Format data failed\n");
  1058. X#endif
  1059. X        goto fail;
  1060. X    }
  1061. X
  1062. X    return(doc);
  1063. X
  1064. Xfail:
  1065. X    if(doc) {freefile(doc); doc=0;}
  1066. X    if(oserr) {
  1067. X#ifdef DEBUG5
  1068. X        dmsg(5,"getfile: error %ld, %s\n",oserr,errortext[errnum(oserr)].text);
  1069. X#endif
  1070. X    }
  1071. X    return(0);
  1072. X}
  1073. X
  1074. Xstruct doc *
  1075. Xreadfile(name)
  1076. X    u_char *name;
  1077. X{
  1078. X    struct FileInfoBlock *fileinfo=0;
  1079. X    struct  Lock *lock=0,*Lock();        /* to get info about the disk */
  1080. X    struct doc *doc=0;
  1081. X    int i;
  1082. X    long len, fh=0, Open();
  1083. X    struct openwindows *ow;
  1084. X
  1085. X    oserr=103;
  1086. X    len=strlen(name)+1; /* Make sure that we compare the \0 at the end too */
  1087. X    if( (doc=(struct doc *)AllocMem(sizeof(struct doc),MEMF_CLEAR|MEMF_NAMED,"readfile2"))==0) {
  1088. X#ifdef DEBUG5
  1089. X        dmsg(5,"Could not get doc mem=%ld\n",AvailMem(0));
  1090. X#endif
  1091. X        goto fail;
  1092. X    }
  1093. X    for(ow=(struct openwindows*)windowhead.lh_Head ; ow->node.ln_Succ; ow=ow->node.ln_Succ) {
  1094. X        if( strnicmp(ow->doc->body->filename,name,len)==0) {
  1095. X            (*doc)=(*ow->doc);
  1096. X            doc->labs=0;
  1097. X            doc->p=(struct paragraph *)AllocMem(doc->p_count * sizeof(struct paragraph),MEMF_CLEAR|MEMF_NAMED,"Copy of doc");
  1098. X            if(doc->p==0) {
  1099. X                doc->body=0;
  1100. X                goto fail;
  1101. X            }
  1102. X            for(i=0;i<doc->p_count;i++) {
  1103. X                doc->p[i].pindent = ow->doc->p[i].pindent;
  1104. X                doc->p[i].indent = ow->doc->p[i].indent;
  1105. X                doc->p[i].data = ow->doc->p[i].data;
  1106. X                doc->p[i].length = ow->doc->p[i].length;
  1107. X            }
  1108. X            doc->body->usecount++;
  1109. X            doc->pnum=doc->lnum=0;
  1110. X            doc->savefont=0;
  1111. X            break;
  1112. X        }
  1113. X    }
  1114. X    if(!doc->body) {
  1115. X        if( (fileinfo=(struct FileInfoBlock *)AllocMem(sizeof(struct FileInfoBlock),0|MEMF_NAMED,"readfile1"))==0) {
  1116. X#ifdef DEBUG5
  1117. X            dmsg(5,"Could not get FileInfoBlock mem=%ld\n",AvailMem(0));
  1118. X#endif
  1119. X            goto fail;
  1120. X        }
  1121. X        if( (lock=Lock(name,ACCESS_READ))==0) {
  1122. X#ifdef DEBUG5
  1123. X            dmsg(5,"Could not get lock\n");
  1124. X#endif
  1125. X            oserr=IoErr();
  1126. X            goto fail;
  1127. X        }
  1128. X        if(0==Examine(lock,fileinfo)){
  1129. X#ifdef DEBUG5
  1130. X            dmsg(5,"Could not examine\n");
  1131. X#endif
  1132. X            oserr=IoErr();
  1133. X            goto fail;
  1134. X        }
  1135. X        if(fileinfo->fib_DirEntryType>=0){
  1136. X#ifdef DEBUG5
  1137. X            dmsg(5,"ERROR: FILE is directory\n");
  1138. X#endif
  1139. X            oserr=212;
  1140. X            goto fail;
  1141. X        }
  1142. X        if(fileinfo->fib_Size==0){
  1143. X#ifdef DEBUG6
  1144. X            dmsg(6,"ERROR: SIZE==0\n");
  1145. X#endif
  1146. X            oserr=212;
  1147. X            goto fail;
  1148. X        }
  1149. X
  1150. X        if( (doc->body=(struct textbody *)AllocMem(sizeof(struct textbody),MEMF_CLEAR|MEMF_NAMED,"readfile textbody"))==0) {
  1151. X#ifdef DEBUG5
  1152. X            dmsg(5,"Could not alloc textbody size");
  1153. X#endif
  1154. X            goto fail;
  1155. X        }
  1156. X        doc->body->length=fileinfo->fib_Size;
  1157. X
  1158. X        if(strncpy(doc->body->comment,fileinfo->fib_Comment,COMWIDTH)==0) {
  1159. X            (void)strncpy(doc->body->comment,name,COMWIDTH);
  1160. X        }
  1161. X        doc->body->comment[COMWIDTH-1]=0;
  1162. X        if (fileinfo) FreeMem(fileinfo,sizeof(struct FileInfoBlock));
  1163. X        fileinfo=0;
  1164. X        if( (doc->body->text=(char *)AllocMem(doc->body->length,0|MEMF_NAMED,"readfile3"))==0) {
  1165. X#ifdef DEBUG5
  1166. X            dmsg(5,"Could not alloc body size=%ld, mem=%ld\n",doc->body->length,AvailMem(0));
  1167. X#endif
  1168. X            goto fail;
  1169. X        }
  1170. X        doc->body->usecount++;
  1171. X
  1172. X        if( (fh=Open(name,1005))==0){
  1173. X#ifdef DEBUG5
  1174. X            dmsg(5,"Could not OPEN\n");
  1175. X#endif
  1176. X            oserr=IoErr();
  1177. X            goto fail;
  1178. X        }
  1179. X        UnLock(lock);
  1180. X        len=Read(fh,doc->body->text,doc->body->length);
  1181. X        if(len!=doc->body->length) {
  1182. X#ifdef DEBUG5
  1183. X            dmsg(5,"getfile: Read failed, read %ld bytes out of %ld total length\n",len,doc->body->length);
  1184. X#endif
  1185. X            oserr=IoErr();
  1186. X            goto fail;
  1187. X        }
  1188. X
  1189. X        oserr=0;
  1190. X        Close(fh);
  1191. X
  1192. X        if(0==(doc->body->filename=(char *)AllocMem(strlen(name)+1,MEMF_NAMED,"readfilename"))) {
  1193. X#ifdef DEBUG5
  1194. X            dmsg(5,"getfile: Could not save filename\n");
  1195. X#endif
  1196. X            oserr=103;
  1197. X            goto fail;
  1198. X        }
  1199. X        strncpy(doc->body->filename,name,strlen(name)+1);
  1200. X    }
  1201. X    return(doc);
  1202. X
  1203. Xfail:
  1204. X#ifdef DEBUG5
  1205. X    dmsg(5,"getfile: ReadFile Failed!\n");
  1206. X#endif
  1207. X    /* pause("WAITING..."); */
  1208. X    if (lock)     UnLock(lock);
  1209. X    if (doc) {
  1210. X        if(doc->body) {
  1211. X            if(doc->body->usecount) doc->body->usecount--;
  1212. X       /* NOTE: There is no need to check for paragraphs here. */
  1213. X            if(doc->body->usecount==0) {
  1214. X                if(doc->body->text) {
  1215. X                    FreeMem(doc->body->text,doc->body->length);
  1216. X                    doc->body->text=0;
  1217. X                }
  1218. X                if(doc->body->filename) {
  1219. X                    FreeMem(doc->body->filename,strlen(doc->body->filename)+1);
  1220. X                }
  1221. X                FreeMem(doc->body,sizeof(struct textbody));
  1222. X                doc->body=0;
  1223. X            }
  1224. X        }
  1225. X        FreeMem(doc,sizeof(struct doc));
  1226. X    }
  1227. X    if (fh) Close(fh);
  1228. X    if (fileinfo) FreeMem(fileinfo,sizeof(struct FileInfoBlock));
  1229. X    return(0);
  1230. X}
  1231. X
  1232. Xvoid
  1233. Xfreefile(doc)
  1234. X    struct doc *doc;
  1235. X{
  1236. X    int i;
  1237. X
  1238. X    if(doc->body) {
  1239. X        if(doc->body->usecount) doc->body->usecount--;
  1240. X        if(doc->body->usecount==0) {
  1241. X            if(doc->body->text) {
  1242. X                FreeMem(doc->body->text,doc->body->length);
  1243. X                doc->body->text=0;
  1244. X            }
  1245. X            if(doc->body->filename) {
  1246. X                FreeMem(doc->body->filename,strlen(doc->body->filename)+1);
  1247. X            }
  1248. X
  1249. X            if(doc->body->font.ta_Name) {
  1250. X                FreeMem(doc->body->font.ta_Name, strlen(doc->body->font.ta_Name)+1);
  1251. X            }
  1252. X            doc->body->font.ta_Name=0;
  1253. X            FreeMem(doc->body,sizeof(struct textbody));
  1254. X            doc->body=0;
  1255. X        }
  1256. X    }
  1257. X    if(doc->labs && doc->lab_count) {
  1258. X        FreeMem(doc->labs, sizeof(struct labels)*doc->lab_count);
  1259. X    }
  1260. X    doc->labs=0;
  1261. X    for(i=0;i<doc->p_count;i++) {
  1262. X        if(doc->p[i].count && doc->p[i].lines) {
  1263. X            FreeMem(doc->p[i].lines, doc->p[i].count * sizeof(struct displaylines));
  1264. X            doc->p[i].lines=0;
  1265. X        }
  1266. X    }
  1267. X    FreeMem(doc->p,doc->p_count*sizeof(struct paragraph));
  1268. X    doc->p=0;
  1269. X    doc->body=0;
  1270. X
  1271. X    /* if(doc->propwidth) { */
  1272. X        /* FreeMem(doc->propwidth,256); */
  1273. X        /* doc->propwidth=0; */
  1274. X    /* } */
  1275. X    FreeMem(doc,sizeof(struct doc));
  1276. X}
  1277. X
  1278. X
  1279. Xstruct doc *
  1280. Xpbreakfile(doc)
  1281. X    struct doc *doc;
  1282. X{
  1283. X    register u_char c, *begin, *body=doc->body->text;
  1284. X    register u_long size=doc->body->length, marksize;
  1285. X    u_char *markbody, *command, tmpchar;
  1286. X    u_short c_len, flags=0, inc;
  1287. X    u_short p_count=0, refmark=0;
  1288. X    int i;
  1289. X    struct paragraph *p=0;
  1290. X
  1291. X    sleft=stop=swidth=sheight=-1;
  1292. X    /* Check to see if this is a HyperHelp file ( Begins with a (@ @) )*/
  1293. X    if(doc->body->usecount>1) return doc;
  1294. X    else {
  1295. X        if(ENVFont) {
  1296. X            i=strlen(ENVFont->ta_Name)+1;
  1297. X            doc->body->font = *ENVFont;
  1298. X            doc->body->font.ta_Name = (STRPTR)AllocMem(i,0|MEMF_NAMED,"pbreak0");
  1299. X            if(doc->body->font.ta_Name==0) {
  1300. X                doc->body->font.ta_YSize=0;
  1301. X            } else {
  1302. X                strncpy(doc->body->font.ta_Name,ENVFont->ta_Name,i);
  1303. X            }
  1304. X        }
  1305. X        begin=body;
  1306. X        if( size>1 && body[0]=='(' && body[1]=='@' ) {
  1307. X            flags=DOC_FORMATED;
  1308. X
  1309. X            while(size>0) {
  1310. X                switch( c=*body++ ) {
  1311. X                case 0:
  1312. X                    *body=32;
  1313. X                    break;
  1314. X                case '\t':
  1315. X                    break;
  1316. X                case '\n':
  1317. X                    *(body-1) = 32;
  1318. X                    if( *body=='\n' && size>1 ) {
  1319. X                        *(body-1)=0;
  1320. X                        *body=0;
  1321. X                        p_count++;
  1322. X                        size--;
  1323. X                        body++;
  1324. X                    }
  1325. X                    break;
  1326. X                case '(':
  1327. X                    if(*body=='@' && size>1 ) {
  1328. X                        markbody = body-1;
  1329. X                        marksize = size;
  1330. X                        /* *(body-1) = 0; */
  1331. X                        command=body+1;
  1332. X                        size-=2;
  1333. X                        c_len=0;
  1334. X                        inc=1;
  1335. X                        while(size>0) {
  1336. X                            if(*body<=' ') {
  1337. X                                *body=' ';
  1338. X                                if(inc!=0) {
  1339. X                                    inc=0;
  1340. X                                    c_len--;
  1341. X                                }
  1342. X                                body++;
  1343. X                            } else if( *body == '@' && (*(body+1) == ')' && size>1)) {
  1344. X                                body++;
  1345. X                                break;
  1346. X                            } else if( *body++ == '(' && (*body == '@' && size>1)) {
  1347. X                                body=markbody+2;
  1348. X                                size = marksize -1;
  1349. X                                marksize=0;
  1350. X#ifdef DEBUG6
  1351. X                                dmsg(6,"getfile: NESTED COMMAND NOT ALLOWED!\n");
  1352. X#endif
  1353. X                                break;
  1354. X                            }
  1355. X                            size--;
  1356. X                            c_len+=inc;
  1357. X                        }
  1358. X                        if(size==0 || marksize==0) {   /* ERROR Reached EOF before finding '@)' */
  1359. X#ifdef DEBUG6
  1360. X                            if(marksize!=0) dmsg(6,"getfile: ERROR -- no closeing '@)'.\n");
  1361. X#endif
  1362. X                            break;
  1363. X                        }
  1364. X                        *body = 1;
  1365. X                        if(c_len>1)tmpchar = token(command,c_len-1);
  1366. X                        if(c_len<=1 || tmpchar!=0) {
  1367. X                            *(body-1)=0; /* set a null byte for end of string*/
  1368. X                            markbody[0]=0; /* set open paren to \0 */
  1369. X                            *(command-1) = body-command+3;
  1370. X                            switch(tmpchar) {
  1371. X                                case 0:
  1372. X                                    tmpchar=STYLE_INVALID;
  1373. X                                    break;
  1374. X                                case STYLE_NORMAL:
  1375. X                                case STYLE_UNDERLINE:
  1376. X                                case STYLE_BOLD:
  1377. X                                case STYLE_ITALIC:
  1378. X                                case STYLE_COLOR:
  1379. X                                    break;
  1380. X                                case STYLE_WINDOW:
  1381. X                                    {
  1382. X                                        u_char *ptr;
  1383. X                                        int top=TOP,left=LEFT,width=WIDTH,height=HEIGHT;
  1384. X
  1385. X                                        ptr=scannum(command+7,&top);
  1386. X                                        ptr=scannum(ptr,&left);
  1387. X                                        ptr=scannum(ptr,&width);
  1388. X                                        ptr=scannum(ptr,&height);
  1389. X                                        if(top+height<=screenHEIGHT && left+width<=screenWIDTH) {
  1390. X                                            dmsg(1,"Setting top=%ld, height=%ld.\n",top,height);
  1391. X                                            dmsg(1,"Setting left=%ld, width=%ld.\n",left,width);
  1392. X                                            sleft=left;
  1393. X                                            stop=top;
  1394. X                                            swidth=width;
  1395. X                                            sheight=height;
  1396. X                                        }
  1397. X                                    }
  1398. X                                    break;
  1399. X                                case STYLE_REF:
  1400. X                                case STYLE_EXEC:
  1401. X                                    if(refmark) {
  1402. X#ifdef DEBUG6
  1403. X                                        dmsg(6,"getfile: Error, nested REFs not allowed\n");
  1404. X#endif
  1405. X                                        tmpchar=STYLE_INVALID;
  1406. X                                    } else refmark=1;
  1407. X                                    break;
  1408. X                                case STYLE_UNREF:
  1409. X                                    if(refmark)
  1410. X                                        refmark=0;
  1411. X                                    else {
  1412. X#ifdef DEBUG6
  1413. X                                        dmsg(6,"getfile: UNREF missing matching REF or EXECUTE\n");
  1414. X#endif
  1415. X                                        tmpchar=STYLE_INVALID;
  1416. X                                    }
  1417. X                                    break;
  1418. X                                case STYLE_FONT:
  1419. X                                    /* (@font topaz.font 8@) */
  1420. X                                    if (!NoSetFont) {
  1421. X                                        int j,t=0;
  1422. X                                        for(j=5;command[j]!=0 && command[j]!=' ';j++);
  1423. X                                        /* j-=5; */
  1424. X                                        if(doc->body->font.ta_Name) {
  1425. X                                            FreeMem(doc->body->font.ta_Name, strlen(doc->body->font.ta_Name)+1);
  1426. X                                        }
  1427. X                                        doc->body->font.ta_Name = (STRPTR) AllocMem(j-4,0|MEMF_NAMED,"pbreak1");
  1428. X                                        if(doc->body->font.ta_Name) {
  1429. X                                            strncpy(doc->body->font.ta_Name,command+5,j-5);
  1430. X                                            doc->body->font.ta_Name[j-5]=0;
  1431. X#ifdef DEBUG1
  1432. X                                            dmsg(1,"getfile: Font name is '%s'\t",doc->body->font.ta_Name);
  1433. X#endif
  1434. X                                            while(command[j]==' ')j++;
  1435. X                                            while(command[j]<='9' && command[j]>='0') {
  1436. X                                                t=t*10+ command[j]-'0';
  1437. X                                                j++;
  1438. X                                            }
  1439. X                                            doc->body->font.ta_YSize=t;
  1440. X#ifdef DEBUG1
  1441. X                                            dmsg(1,"getfile: Font height =%ld.\n",t);
  1442. X#endif
  1443. X                                        }
  1444. X                                    }
  1445. X                                    break;
  1446. X                                case STYLE_TITLE:
  1447. X                                    /* (@title This windows title */
  1448. X                                    strncpy(doc->body->comment,command+6,COMWIDTH);
  1449. X                                    doc->body->comment[COMWIDTH-1]=0;
  1450. X                                    break;
  1451. X                                case STYLE_LSPACE:
  1452. X                                    if(command[7]>='0' && command[7]<='9') {
  1453. X                                        doc->linespace = (command[7]-'0');
  1454. X#ifdef DEBUG1
  1455. X                                        dmsg(1,"getfile:linespace set to %ld.\n",doc->linespace);
  1456. X#endif
  1457. X                                    }
  1458. X                                    break;
  1459. X                                case STYLE_INDENT:
  1460. X                                case STYLE_PINDENT:
  1461. X                                    break;
  1462. X                                case STYLE_LABEL:
  1463. X                                    doc->lab_count++;
  1464. X                                    break;
  1465. X                                default:
  1466. X#ifdef DEBUG9
  1467. X                                    dmsg(9,"ERROR: GETFILE.c -> Unknown STLYE=%lx.\n",tmpchar);
  1468. X#endif
  1469. X                                    break;
  1470. X                            }
  1471. X                            *command++=tmpchar;
  1472. X                            body++;
  1473. X                        } else {
  1474. X#ifdef DEBUG6
  1475. X                            dmsg(6,"getfile: UNRECOGNIZED COMMAND c_len=%ld, tmpchar=%ld\n",c_len,tmpchar);
  1476. X#endif
  1477. X                            body++;
  1478. X                        }
  1479. X                    }
  1480. X                    break;
  1481. X                default:
  1482. X                    if(c<32) {
  1483. X#ifdef DEBUG6
  1484. X                        dmsg(6,"getfile: ERROR Illegal character 0x%lx in textfile.\n",(long)c);
  1485. X#endif
  1486. X                        *(body-1)=0;
  1487. X                    }
  1488. X                    break;
  1489. X                }
  1490. X                size--;
  1491. X            } /* end while(size>0) for formatted text */
  1492. X        } else {
  1493. X            while(size>0) {
  1494. X                switch( c=*body++ ) {
  1495. X                case '\n':
  1496. X                    *(body-1)=0;
  1497. X                    p_count++;
  1498. X                    break;
  1499. X                case '\t':
  1500. X                    break;
  1501. X                default:
  1502. X                    if( c<32) {
  1503. X                        *(body-1)=32;
  1504. X                    }
  1505. X                    break;
  1506. X                }
  1507. X                size--;
  1508. X            }
  1509. X        }
  1510. X    }
  1511. X#ifdef DEBUG"\33[32mPBREAK\33[31m SIZE=%ld
  1512. X    /* dmsg("\33[32mPBREAK\33[31m SIZE=%ld, body-begin=%ld\n",size,body-doc->body); */
  1513. X#endif
  1514. X    p=(struct paragraph *)AllocMem(sizeof(struct paragraph)*(p_count+1),MEMF_CLEAR|MEMF_NAMED,"pbreak2");
  1515. X    if(p==0) {
  1516. X        goto fail;
  1517. X    }
  1518. X#ifdef DEBUG1
  1519. X    dmsg(1,"p=%lx, doc=%lx, doc->body=%lx end=%lx ",p,doc,doc->body, doc->body+doc->body->length);
  1520. X#endif
  1521. X#ifdef DEBUG1
  1522. X    dmsg(1,"Pcount=%ld\n",p_count);
  1523. X#endif
  1524. X    doc->p = p;
  1525. X    doc->p_count=p_count+1;
  1526. X    body=doc->body->text;
  1527. X    doc->p[0].data=body;
  1528. X    doc->flags |= flags;
  1529. X    for(i=1;i<=p_count;i++) {
  1530. X        if(flags & DOC_FORMATED) {
  1531. X            while(*body!=0 || *(body+1)!=0) {
  1532. X                body++;
  1533. X            }
  1534. X            doc->p[i-1].length=body- doc->p[i-1].data;
  1535. X            body++;
  1536. X        } else {
  1537. X            while(*body!=0 ) {
  1538. X                body++;
  1539. X            }
  1540. X            doc->p[i-1].length=body- doc->p[i-1].data;
  1541. X        }
  1542. X        body++;
  1543. X        doc->p[i].data=body;
  1544. X    }
  1545. X    i--;
  1546. X    doc->p[i].length= ((long)doc->body->text)+doc->body->length-(long)body;
  1547. X#ifdef DEBUG1
  1548. X    dmsg(1,"i=%ld, LastLen=%ld\n",i,doc->p[i].length);
  1549. X#endif
  1550. X    /*
  1551. X    {
  1552. X        int j;
  1553. X        for(j=doc->p[i].length-1;j>=0;j--) {
  1554. X            if(doc->p[i].data[j]<32) doc->p[i].length--; else break;
  1555. X        }
  1556. X    }
  1557. X    */
  1558. X    return(doc);
  1559. X
  1560. Xfail:
  1561. X#ifdef DEBUG1
  1562. X    dmsg(1,"getfile: PBREAK FAILED\n");
  1563. X#endif
  1564. X    if(doc && doc->body->font.ta_Name) {
  1565. X        FreeMem(doc->body->font.ta_Name, strlen(doc->body->font.ta_Name)+1);
  1566. X        doc->body->font.ta_Name=0;
  1567. X    }
  1568. X
  1569. X    return(0);
  1570. X}
  1571. X
  1572. Xu_char *
  1573. Xscannum(ptr, num)
  1574. X    u_char *ptr;
  1575. X    int *num;
  1576. X{
  1577. X    register int n=0;
  1578. X    if(ptr==0) return 0;
  1579. X    while(*ptr==' ' || *ptr=='\t') ptr++;
  1580. X    if (!(*ptr>='0' && *ptr<='9')) return 0;
  1581. X    while(*ptr>='0' && *ptr<='9') {
  1582. X        n = n*10+ ptr[0]-'0';
  1583. X        ptr++;
  1584. X    }
  1585. X    *num=n;
  1586. X    while(*ptr==' ' || *ptr=='\t') ptr++;
  1587. X    if(*ptr==',' || *ptr=='/') ptr++;
  1588. X    if(*ptr==0) return 0;
  1589. X    dmsg(1,"Scan returns n=%ld.\n",n);
  1590. X    return ptr;
  1591. X}
  1592. X
  1593. SHAR_EOF
  1594. echo "extracting grandcentral.c"
  1595. sed 's/^X//' << \SHAR_EOF > grandcentral.c
  1596. X/* HyperHelp -- Copyright 1989 Joe Porkka */
  1597. X
  1598. X/* grandcentral.c -- The "main" loop of the program. Handles all the
  1599. X             input events, and manages the windows
  1600. X*/
  1601. X
  1602. X/* #define DEBUG1 */
  1603. X#include <intuition/intuition.h>
  1604. X#include <exec/io.h>
  1605. X#include <exec/memory.h>
  1606. X#include "help.h"
  1607. X#include "helptext.h"
  1608. Xextern int ScreenType;
  1609. Xextern struct NewWindow nw;
  1610. Xextern int debug;
  1611. Xextern char *RootFile;
  1612. Xextern struct Screen *screen;
  1613. Xextern struct List windowhead;
  1614. Xextern short windowcount;
  1615. Xextern struct MsgPort *mp;
  1616. X
  1617. Xextern ULONG ENVRefresh, ENVNumClicks, ENVAskFirst;
  1618. Xextern struct Task *mytask;
  1619. X
  1620. X/* From print.c */
  1621. Xextern struct IOStdReq *printreq;
  1622. Xint printing, printbuflen;
  1623. Xu_char *printbuf;
  1624. Xstruct openwindows *printow;
  1625. X
  1626. X#define SETREFRESH(ow) ((struct openwindows *)ow)->flags|=ow_REFRESH
  1627. X#define CLRREFRESH(ow) ((struct openwindows *)ow)->flags&=~ow_REFRESH
  1628. X
  1629. X#define KEY_UP      0x4c
  1630. X#define KEY_DOWN  0x4d
  1631. X#define KEY_RIGHT 0x4e
  1632. X#define KEY_LEFT  0x4f
  1633. X#define KEY_ESC   0x45
  1634. X#define KEY_C      0x33
  1635. X
  1636. X#define QUAL_SHIFT 0X003
  1637. X#define QUAL_CTRL  0X008
  1638. X#define QUAL_ALT   0X030
  1639. X#define QUAL_REPT  0X200
  1640. X
  1641. Xextern ULONG lastclicksecs, lastclickmicros; /* From GC2.C */
  1642. Xshort openroot, closeall, hideall, goaway, findabout;
  1643. XULONG prevsecs=0, prevmicros=0;
  1644. Xu_short clickx, clicky, clickcount;
  1645. Xstruct key key;
  1646. Xint wide, high;
  1647. Xshort checkflags;
  1648. X
  1649. Xint
  1650. Xgrandcentral()
  1651. X{
  1652. X    struct openwindows *tmpow, *ow;
  1653. X    struct IntuiMessage *im, *im2, *succ, *GetMsg();
  1654. X    unsigned long sigs;
  1655. X    short   countdown,dir;
  1656. X    ULONG Class;
  1657. X    USHORT Code;
  1658. X    USHORT Qualifier;
  1659. X
  1660. X    lastclicksecs = lastclickmicros =0;
  1661. X    prevsecs=0, prevmicros=0;
  1662. X    openroot=1; /* make the root file open immediatly */
  1663. X    closeall=0; hideall=0; goaway=0; findabout=0;
  1664. X    countdown=0; dir=0; checkflags=0;
  1665. X    printing=0; printow=0; printbuf=0; printbuflen=0;
  1666. X    printreq=0;
  1667. X
  1668. X    do {
  1669. X    if(closeall) {
  1670. X        closeall=0;
  1671. X        hideall=0;
  1672. X        openroot=1;
  1673. X#ifdef DEBUG1
  1674. X        dmsg(1,"Closing all windows!\n");
  1675. X#endif
  1676. X        closeallwindows();
  1677. X#ifdef DEBUG1
  1678. X        dmsg(1,"All closed, waiting for hotkey.\n");
  1679. X#endif
  1680. X        if(waitforhotkey()==0)  return 0;
  1681. X    }
  1682. X
  1683. X    if(goaway) {
  1684. X        goaway=0;
  1685. X        return 0; /* Cause main() to call die() to clean things up */
  1686. X    }
  1687. X    if(hideall) {
  1688. X        closeall=0;
  1689. X        hideall=0;
  1690. X#ifdef DEBUG1
  1691. X        dmsg(1,"Hideing all windows\n");
  1692. X#endif
  1693. X        for(ow=(struct openwindows*)windowhead.lh_Head ; ow->node.ln_Succ; ow=ow->node.ln_Succ) {
  1694. X        if(!(ow->flags & ow_PRINTING)) {
  1695. X            getdims(ow);
  1696. X            CWS(ow->window, ow->doc->savefont);
  1697. X            ow->window=0;
  1698. X        }
  1699. X        }
  1700. X        if(screen) {
  1701. X        CloseScreen(screen);
  1702. X        screen=0;
  1703. X        }
  1704. X#ifdef DEBUG1
  1705. X        dmsg(1,"Waiting for hot key\n");
  1706. X#endif
  1707. X        if(waitforhotkey()==0)  return 0;
  1708. X#ifdef DEBUG1
  1709. X        dmsg(1,"Got hot key, opening windows\n");
  1710. X#endif
  1711. X        if(ScreenType!=0 && screen==0) customscreen();
  1712. X
  1713. X        checkflags=0;
  1714. X        for(ow=(struct openwindows*)windowhead.lh_Head ; ow->node.ln_Succ; ow=ow->node.ln_Succ) {
  1715. X        if(!(ow->flags & ow_PRINTING)) {
  1716. X            flipwindow(ow,1);
  1717. X            checkflags++;
  1718. X        }
  1719. X        }
  1720. X#ifdef DEBUG1
  1721. X        dmsg(1,"Windows all open!\n");
  1722. X#endif
  1723. X        if(windowcount==0) {
  1724. X#ifdef DEBUG1
  1725. X        dmsg(1,"Failed to open any windows :-( \n");
  1726. X#endif
  1727. X        return 0;
  1728. X        }
  1729. X        Signal(mytask,0x80000000); /* Make sure we get to the GetMsg() call */
  1730. X    }
  1731. X    if(openroot){
  1732. X        openroot=0;
  1733. X        closeall=hideall=0;
  1734. X        ow=getfile(RootFile);
  1735. X        if(ow==0 && windowcount==0) {
  1736. X#ifdef DEBUG1
  1737. X        dmsg(1,"Could not open initial file.");
  1738. X#endif
  1739. X        return 0;
  1740. X        }
  1741. X        refresh(ow);
  1742. X    }
  1743. X    if(checkflags) {
  1744. X#ifdef DEBUG1
  1745. X        dmsg(1,"$=%ld ",checkflags);
  1746. X#endif
  1747. X        for(tmpow=(struct openwindows *)windowhead.lh_Head;tmpow->node.ln_Succ;tmpow=tmpow->node.ln_Succ) {
  1748. X        if(tmpow->window && tmpow->flags & ow_REFRESH) {
  1749. X            if(checkflags) checkflags--;
  1750. X            refresh(tmpow);
  1751. X            tmpow->flags&=~ow_REFRESH;
  1752. X        }
  1753. X        if((!printing) && tmpow->window && tmpow->flags & (ow_PRINTFILE | ow_PRINTWINDOW)) {
  1754. X            static UBYTE *wt, *st;
  1755. X            static int test;
  1756. X            static char *printwait="Opening printer.device";
  1757. X
  1758. X            if(checkflags) checkflags--;
  1759. X            printing=0; /* Just to be sure. */
  1760. X            wt=tmpow->window->Title;
  1761. X            st=tmpow->window->ScreenTitle;
  1762. X            SetWindowTitles(tmpow->window,printwait,printwait);
  1763. X            test=printinit(mp);
  1764. X            SetWindowTitles(tmpow->window,wt,st);
  1765. X            if(test==0) {
  1766. X#ifdef DEBUG5
  1767. X            dmsg(5,"Could not init printer!\n");
  1768. X#endif
  1769. X            tmpow->flags&= ~(ow_PRINTFILE | ow_PRINTWINDOW);
  1770. X            } else {
  1771. X            if(tmpow->flags & ow_PRINTWINDOW) {
  1772. X                high=tmpow->high;
  1773. X                wide=tmpow->wide;
  1774. X            } else {
  1775. X                getprintwidth(&wide, &high);
  1776. X                high=0;
  1777. X            }
  1778. X            tmpow->flags&= ~(ow_PRINTFILE | ow_PRINTWINDOW);
  1779. X            printbuf=(u_char *)AllocMem(wide+wide,MEMF_NAMED,"Print buffer");
  1780. X            if(printbuf==0) {
  1781. X#ifdef DEBUG5
  1782. X                dmsg(5,"No mem for print buf!\n");
  1783. X#endif
  1784. X                printdnit();
  1785. X            } else {
  1786. X                printbuflen=wide+wide;
  1787. X                printow=getprintfile(tmpow->doc->body->filename,wide);
  1788. X#ifdef DEBUG1
  1789. X                dmsg(1,"GOTFILE!! WINDOWCOUNT=%ld.\n",windowcount);
  1790. X#endif
  1791. X                if(printow==0) {
  1792. X#ifdef DEBUG5
  1793. X                dmsg(5,"Could not getprintfile!\n");
  1794. X#endif
  1795. X                printdnit();
  1796. X                } else {
  1797. X                printow->flags |= ow_PRINTING;
  1798. X#ifdef DEBUG1
  1799. X                dmsg(1,"Sending FIRST printmessage\n");
  1800. X#endif
  1801. X                printit("\033#1"); /* reinitialize aRIN */
  1802. X                printing=1;
  1803. X                if(high) { /* Set begining position if printing from window */
  1804. X                    printow->doc->pnum=tmpow->doc->pnum;
  1805. X                    printow->doc->lnum=tmpow->doc->lnum;
  1806. X                }
  1807. X                }
  1808. X            }
  1809. X            }
  1810. X        }
  1811. X        }
  1812. X    }
  1813. X    /* pause("Wait for input signal"); */
  1814. X    if(windowcount==0) {
  1815. X#ifdef DEBUG1
  1816. X        dmsg(1,"Attempt to wait while no windows open.\n");
  1817. X#endif
  1818. X        return 0;
  1819. X    }
  1820. X    sigs=Wait(-1);
  1821. X    while( (im=GetMsg(mp))!=0) {
  1822. X#ifdef DEBUG1
  1823. X        dmsg(1,"LOOP ");
  1824. X#endif
  1825. X        if( (printreq==(struct IOStdReq *)im) && printing && printreq) {
  1826. X        if(printreq->io_Error) {
  1827. X#ifdef DEBUG5
  1828. X            dmsg(5,"print error!\n");
  1829. X#endif
  1830. X            printing=5;
  1831. X        }
  1832. X        switch(printing) {
  1833. X            case 1: /* Just put out the aRIN, now put the filename */
  1834. X            printit(printow->doc->body->filename);
  1835. X            printing=2;
  1836. X            break;
  1837. X            case 2: /* Now put out a cr */
  1838. X            printit("\n");
  1839. X            printing=3;
  1840. X            break;
  1841. X            case 3:
  1842. X            displayline(0,&printow->doc->p[printow->doc->pnum],printow->doc->lnum,printow,printbuf,printbuflen);
  1843. X            printit(printbuf);
  1844. X            printing=2;
  1845. X            printow->doc->lnum++;
  1846. X            if(printow->doc->lnum >= printow->doc->p[printow->doc->pnum].count) {
  1847. X                printow->doc->lnum=0;
  1848. X                printow->doc->pnum++;
  1849. X                if(printow->doc->pnum >= printow->doc->p_count) {
  1850. X                printing=4; /* end of doc */
  1851. X                }
  1852. X            }
  1853. X            if(high) {
  1854. X                high--;
  1855. X                if(high==0) printing=4; /* End of window */
  1856. X            }
  1857. X            break;
  1858. X            case 4: /* Now put out a cr, FF, aRIN */
  1859. X            printit("\n\14\33#1");
  1860. X            printing=5;
  1861. X            break;
  1862. X            case 5: /* Stop printing */
  1863. X    xcancelprintjob:
  1864. X#include "kludge.h"
  1865. X            /* cancelprintjob(); /* This call calls the guru, so inline the function */ */
  1866. X            printing=0;
  1867. X#ifdef DEBUG1
  1868. X            dmsg(1,"   GC %ld %ld %ld \n",printing,printreq,printbuf);
  1869. X#endif
  1870. X            break;
  1871. X            case 6: /* Abort all printing */
  1872. X            printit("\33c"); /* Hard reset, to empty buffer */
  1873. X            printing=7;
  1874. X            break;
  1875. X            case 7: /* Now remove any pending jobs */
  1876. X            for(tmpow=(struct openwindows*)windowhead.lh_Head ; tmpow->node.ln_Succ; tmpow=tmpow->node.ln_Succ) {
  1877. X                tmpow->flags &= ~(ow_PRINTFILE | ow_PRINTWINDOW);
  1878. X            }
  1879. X#ifdef DEBUG1
  1880. X            dmsg(1,"Now removeing current job.\n");
  1881. X#endif
  1882. X            goto xcancelprintjob; /* To avoid too many copies
  1883. X                        of kludge.h
  1884. X                          */
  1885. X            /* break; */
  1886. X        }
  1887. X        continue;
  1888. X        }
  1889. X        tmpow= (struct openwindows *)im->IDCMPWindow->UserData;
  1890. X        Class=im->Class;
  1891. X        Code=im->Code;
  1892. X        Qualifier=im->Qualifier;
  1893. X        if(Class==RAWKEY) {
  1894. X        switch(Code) {
  1895. X            case KEY_UP:
  1896. X            Class=GADGETDOWN;
  1897. X            im->IAddress = (APTR) tmpow->up;
  1898. X            break;
  1899. X            case KEY_DOWN:
  1900. X            Class=GADGETDOWN;
  1901. X            im->IAddress = (APTR)tmpow->down;
  1902. X            break;
  1903. X            case KEY_UP+128:
  1904. X            Class=GADGETUP;
  1905. X            im->IAddress = (APTR)tmpow->up;
  1906. X            break;
  1907. X            case KEY_DOWN+128:
  1908. X            Class=GADGETUP;
  1909. X            im->IAddress = (APTR)tmpow->down;
  1910. X            break;
  1911. X            default:
  1912. X            Code=0;
  1913. X            Class=0;
  1914. X            break;
  1915. X        } /* Switch (Code) */
  1916. X        /* Remove excess repeat keys from Message port */
  1917. X        if (im->Qualifier & QUAL_REPT) {
  1918. X            Forbid();
  1919. X            im2 = (struct IntuiMessage *)mp->mp_MsgList.lh_Head;
  1920. X            while ( succ=(struct IntuiMessage *)im2->ExecMessage.mn_Node.ln_Succ ) {
  1921. X               if ( im!=im2 && im2->Class==RAWKEY && (im2->Qualifier & QUAL_REPT) ) {
  1922. X              Remove ( im2 );
  1923. X              ReplyMsg( im2 );
  1924. X               }
  1925. X               im2 = succ;
  1926. X            }
  1927. X            Permit();
  1928. X        }
  1929. X        } /* if (Class == RAWKEY) */
  1930. X        switch(Class) {
  1931. X        case 0:
  1932. X        break; /* Ignore NULL Class */
  1933. X        case MOUSEMOVE:
  1934. X        if (! (tmpow->flags & ow_REFRESH)) checkflags++;
  1935. X        scrollit(tmpow);
  1936. X        break;
  1937. X        case GADGETDOWN:
  1938. X#ifdef DEBUG1
  1939. X        /* dmsg(1,"GADGETDOWN '%s', #%ld.\n",im->IDCMPWindow->Title,(long) ((struct Gadget *)im->IAddress)->GadgetID); */
  1940. X#endif
  1941. X        countdown=7; /* .7 second initial delay */
  1942. X        switch( ((struct Gadget *)im->IAddress)->GadgetID ) {
  1943. X            case SCROLLBAR:
  1944. X#ifdef DEBUG1
  1945. X            /* dmsg(1,"SCROLL BAR!\n"); */
  1946. X#endif
  1947. X            if (! (tmpow->flags & ow_REFRESH)) checkflags++;
  1948. X            scrollit(tmpow);
  1949. X            break;
  1950. X            case UPARROW:
  1951. X            dir=-1;
  1952. X            if(Qualifier & QUAL_SHIFT) dir= -tmpow->high;
  1953. X            move( tmpow,dir);
  1954. X            if(dir<-1 || ENVRefresh!=SMART_REFRESH) {
  1955. X                if (! (tmpow->flags & ow_REFRESH)) checkflags++;
  1956. X                SETREFRESH(tmpow);
  1957. X            }
  1958. X            fixscrollgadget(tmpow);
  1959. X            ModifyIDCMP(im->IDCMPWindow,im->IDCMPWindow->IDCMPFlags | INTUITICKS);
  1960. X            break;
  1961. X            case DOWNARROW:
  1962. X            dir=1;
  1963. X            if(Qualifier & QUAL_SHIFT) dir=tmpow->high;
  1964. X            move(tmpow, dir);
  1965. X            if(dir>1 || ENVRefresh!=SMART_REFRESH) {
  1966. X                if (! (tmpow->flags & ow_REFRESH)) checkflags++;
  1967. X                SETREFRESH(tmpow);
  1968. X            }
  1969. X            fixscrollgadget(tmpow);
  1970. X            ModifyIDCMP(im->IDCMPWindow,im->IDCMPWindow->IDCMPFlags | INTUITICKS);
  1971. X            break;
  1972. X            default:
  1973. X            break;
  1974. X        }
  1975. X        break;
  1976. X        case INTUITICKS:
  1977. X        if(countdown) {
  1978. X            countdown--;
  1979. X            if(countdown==0) {
  1980. X            ReplyMsg(im);
  1981. X            if(dir<0) {
  1982. X                if( tmpow->up->Flags & SELECTED) {
  1983. X                move(tmpow,dir);
  1984. X                fixscrollgadget(tmpow);
  1985. X                if (! (tmpow->flags & ow_REFRESH)) checkflags++;
  1986. X                SETREFRESH(tmpow);
  1987. X                countdown=2;
  1988. X                }
  1989. X            } else if(dir>0) {
  1990. X                if( tmpow->down->Flags & SELECTED) {
  1991. X                move( tmpow,dir);
  1992. X                fixscrollgadget(tmpow);
  1993. X                if (! (tmpow->flags & ow_REFRESH)) checkflags++;
  1994. X                SETREFRESH(tmpow);
  1995. X                countdown=2;
  1996. X                }
  1997. X            }
  1998. X            im=0;
  1999. X            }
  2000. X        } else {
  2001. X            ModifyIDCMP(im->IDCMPWindow,im->IDCMPWindow->IDCMPFlags & (~INTUITICKS));
  2002. X        }
  2003. X        break;
  2004. X        case GADGETUP:
  2005. X#ifdef DEBUG1
  2006. X        dmsg(1,"GADGETUP '%s', #%ld.\n",im->IDCMPWindow->Title,(long) ((struct Gadget *)im->IAddress)->GadgetID);
  2007. X#endif
  2008. X        if(  ((struct Gadget *)im->IAddress)->GadgetID ==ICONWINDOW) {
  2009. X            if (! (tmpow->flags & ow_REFRESH)) checkflags++;
  2010. X            if(flipwindow(tmpow,0)==0) goto caseclosewindow;
  2011. X            im=0;
  2012. X        } else {
  2013. X            ModifyIDCMP(im->IDCMPWindow,im->IDCMPWindow->IDCMPFlags & (~INTUITICKS));
  2014. X        }
  2015. X        break;
  2016. X        case MENUPICK:
  2017. X#ifdef DEBUG1
  2018. X        dmsg(1,"MENU PICK  ");
  2019. X#endif
  2020. X        processmenuevent(Code, tmpow->window->MenuStrip, tmpow);
  2021. X        if(findabout) {
  2022. X            findabout=0;
  2023. X            about(tmpow->window);
  2024. X        }
  2025. X        break;
  2026. X        case SIZEVERIFY:
  2027. X#ifdef DEBUG1
  2028. X        dmsg(1,"** SIZEVERIFY **\n");
  2029. X#endif
  2030. X        break;
  2031. X        case NEWSIZE:
  2032. X        tmpow->flags |= ow_SIZED; /* Tell refresh() to update entire window */
  2033. X        /* Prevent another resize, and save the windows' size, then continue */
  2034. X        getdims(tmpow);
  2035. X
  2036. X#ifdef DEBUG1
  2037. X        dmsg(1,"** NEWSZ **\n");
  2038. X#endif
  2039. X        if(sizewindow(im->IDCMPWindow)!=0) {
  2040. X            break;
  2041. X        }
  2042. X        /* refresh(tmpow); */
  2043. X#ifdef DEBUG5
  2044. X        dmsg(5,"****ERROR grandcentral(): size operation failed, closeing window.\n");
  2045. X#endif
  2046. X        /* NOTE: The break is intentionally missing */
  2047. X        case CLOSEWINDOW:
  2048. Xcaseclosewindow:
  2049. X#ifdef DEBUG1
  2050. X        dmsg(1,"Case closewindow\n");
  2051. X#endif
  2052. X        ReplyMsg(im);
  2053. X        closewindow(tmpow);
  2054. X        im=0;
  2055. X        tmpow=0;
  2056. X        break;
  2057. X        case REFRESHWINDOW:
  2058. X        if( tmpow->flags & ow_SIZED) {
  2059. X            /* Clear the damage list, then update the window */
  2060. X            BeginRefresh(im->IDCMPWindow);
  2061. X            EndRefresh(im->IDCMPWindow,-1);
  2062. X            cleardisplay(tmpow);
  2063. X            refresh(tmpow );
  2064. X            tmpow->flags &= ~ ow_SIZED;
  2065. X        } else {
  2066. X            BeginRefresh(im->IDCMPWindow);
  2067. X            refresh(tmpow );
  2068. X            EndRefresh(im->IDCMPWindow,-1);
  2069. X        }
  2070. X        break;
  2071. X        case MOUSEBUTTONS:
  2072. X        switch(Code) {
  2073. X            case SELECTDOWN:
  2074. X#ifdef DEBUG1
  2075. X            dmsg(1,"LEFT DOWN\n");
  2076. X#endif
  2077. X            checkclicks(im,tmpow);
  2078. X            break;
  2079. X            case SELECTUP:
  2080. X#ifdef DEBUG1
  2081. X            dmsg(1,"LEFT UP\n");
  2082. X#endif
  2083. X            countdown=0;
  2084. X            break;
  2085. X            default:
  2086. X            break;
  2087. X        }
  2088. X        break;
  2089. X        default:
  2090. X#ifdef DEBUG9
  2091. X        dmsg(9,"Unknown IntuiMessage->Class=%08lx\n",Class);
  2092. X#endif
  2093. X        break;
  2094. X        }
  2095. X        if(im) ReplyMsg(im);
  2096. X    }
  2097. X    } while( windowcount && !(sigs & 4096));
  2098. X    return 1;
  2099. Xfail:
  2100. X    return 0;
  2101. X}
  2102. SHAR_EOF
  2103. echo "extracting help.h"
  2104. sed 's/^X//' << \SHAR_EOF > help.h
  2105. X/* HyperHelp -- Copyright 1989 Joe Porkka */
  2106. X
  2107. X/* help.h  --  Useful #defines and typedefs + a couple of structs
  2108. X           and function prototypes for everything.
  2109. X*/
  2110. X
  2111. Xtypedef unsigned short u_short;
  2112. Xtypedef unsigned int u_int;
  2113. Xtypedef unsigned long u_long;
  2114. Xtypedef unsigned char u_char;
  2115. Xtypedef unsigned char u_byte;
  2116. X
  2117. X#define DEBUG9
  2118. X#define DEBUG99
  2119. X#define DEBUG10
  2120. X
  2121. X#define AllocMem allocmem
  2122. X#define FreeMem freemem
  2123. X#define MEMF_NAMED 0x10000000
  2124. X
  2125. X#define SCROLLBAR 1
  2126. X#define UPARROW 2
  2127. X#define DOWNARROW 3
  2128. X#define ICONWINDOW 4
  2129. X#define HELPICONWINDOWFLAGS WINDOWDRAG | WINDOWDEPTH | WINDOWCLOSE | SIMPLE_REFRESH | NOCAREREFRESH
  2130. X#define HELPWINDOWFLAGS     WINDOWDRAG | WINDOWDEPTH | WINDOWCLOSE | SIZEBRIGHT | ACTIVATE | WINDOWSIZING
  2131. X
  2132. X#define HELPICONWINDOWIDCMPFLAGS CLOSEWINDOW | MOUSEBUTTONS | GADGETUP | MENUPICK
  2133. X#define HELPWINDOWIDCMPFLAGS     CLOSEWINDOW | MOUSEBUTTONS | MOUSEMOVE | GADGETDOWN | GADGETUP | NEWSIZE | REFRESHWINDOW | RAWKEY | MENUPICK
  2134. X
  2135. X#define HELPWINDOWLIST 'HELP'
  2136. X#define MINX  176
  2137. X#define MINY  55
  2138. X#define TABSTOP 8
  2139. X
  2140. Xstruct key {
  2141. X    u_short length, type; /* type==0 file, type!=0 execute */
  2142. X    u_char *name;
  2143. X};
  2144. Xstruct DOSerror {
  2145. X    int number;
  2146. X    char *text;
  2147. X};
  2148. X
  2149. X/* Functions in "main.c" */
  2150. Xvoid main(int, char *);
  2151. Xint startup();
  2152. Xvoid shutdown();
  2153. Xvoid die(char *);
  2154. Xvoid closewindow(struct openwindows *); /* Should be in windows.c */
  2155. X
  2156. X/* Functions in "images.c" */
  2157. Xvoid getimages( USHORT **, USHORT **, USHORT **);
  2158. X
  2159. X/* Functions in "windows.c" */
  2160. Xvoid CWS(struct Window *, struct TextFont *);
  2161. Xstruct Window *makewindow(struct openwindows *,int,int,int,int,u_char *, struct TextAttr *);
  2162. Xstruct Window *OpenWindow(struct NewWindow *);
  2163. Xvoid closewindowsafely(struct openwindows *);
  2164. Xint sizewindow(struct Window *);
  2165. Xvoid fixscrollgadget(struct openwindows *);
  2166. Xvoid refresh(struct openwindows *);
  2167. X
  2168. X/* Functions in "move.c" */
  2169. Xvoid moveto(struct openwindows*, int);
  2170. Xvoid move(struct openwindows*,int);
  2171. Xint currentlinenum(struct doc *);
  2172. X
  2173. X/* Functions in "fileinit.c" */
  2174. Xint fileinit(void);
  2175. X
  2176. X/* Functions in "format.c" */
  2177. Xint format(struct doc *, int , struct RastPort *);
  2178. X
  2179. X/* Functions in "gen.c" */
  2180. Xchar *arg(int *, char **);
  2181. Xint strncpy(char *, char *, int), strlen(char *);
  2182. Xint strcmp(char *,char *), strnicmp(char *, char *, int);
  2183. Xu_char *strchr(u_char *, u_char);
  2184. Xint strfind(char *, char *);
  2185. X
  2186. X/* Functions in "getfile.c" */
  2187. Xstruct openwindows *getfile(u_char *);
  2188. Xstruct openwindows *getprintfile(u_char *,int);
  2189. Xstruct doc *getdatafile(u_char *);
  2190. Xstruct doc *readfile(char *);
  2191. Xvoid freefile(struct doc *);
  2192. Xu_char token(u_char *, u_long );
  2193. Xstruct doc *pbreakfile(struct doc *);
  2194. Xu_char *scannum(u_char *, int *);
  2195. X
  2196. X/* Functions in "displayline.c" */
  2197. Xvoid displayline(struct RastPort *,struct paragraph *, u_short, struct openwindows *, u_char *, int);
  2198. Xvoid indentbuf(u_char **, int *, int);
  2199. Xvoid copyintobuf(u_char, u_char **, int *, u_char *, int);
  2200. X
  2201. X/* Functions in "findwordinline.c" */
  2202. Xvoid findword(struct openwindows *, int, int, struct key *);
  2203. Xint findwordinline(struct paragraph *,u_short,short, struct key *, u_short *, int);
  2204. X
  2205. X/* Functions in "grandcentral.c" */
  2206. Xint grandcentral();
  2207. X
  2208. X/* Functions in "gc2.c" */
  2209. Xint flipwindow(struct openwindows *, int);
  2210. Xvoid getdims(struct openwindows *);
  2211. Xvoid scrollit(struct openwindows *);
  2212. Xvoid processmenuevent(USHORT, struct Menu *, struct openwindows *);
  2213. Xvoid checkclicks(struct IntuiMessage *, struct openwindows *);
  2214. X
  2215. X/* Functions in "index.c" */
  2216. Xu_char *lookup(u_long, u_char *, int);
  2217. Xvoid index(u_char *, struct key *);
  2218. Xu_long openindexfile(u_char *);
  2219. Xvoid closeindexfile(u_long);
  2220. X
  2221. X/* Functions in "oserr.c" */
  2222. Xint errnum(int);
  2223. X
  2224. X/* Functions in "menu.c" */
  2225. Xvoid makemenu(struct Window *);
  2226. Xvoid removemenu(struct Window *);
  2227. Xvoid initmenus(struct Window *);
  2228. Xvoid domenu(struct Menu *, BYTE *, int *);
  2229. Xvoid domenuitem(struct Menu *, struct MenuItem *, struct IntuiText *, BYTE *, BYTE, int *);
  2230. X
  2231. X/* Functions in "print.c" */
  2232. Xint printinit(struct MsgPort *);
  2233. Xvoid getprintwidth(int *, int *);
  2234. Xvoid printit(u_char *);
  2235. Xvoid printdnit(void);
  2236. X
  2237. X/* Retired Functions */
  2238. Xstruct doc *formatfile(struct RemoveThisDef, struct doc *);
  2239. Xint linebreakfile(struct RemoveThisDef, struct doc *, int);
  2240. Xvoid printline(struct RemoveThisDef, struct paragraph *, u_short);
  2241. Xchar *docommand(struct RemoveThisDef, u_char **, u_long *);
  2242. SHAR_EOF
  2243. echo "End of archive 2 (of 3)"
  2244. # if you want to concatenate archives, remove anything after this line
  2245. exit
  2246.